<?php

namespace app\controllers;

use app\logic\ItemLogic;
use yii\web\HttpException;
use app\components\Controller;

/**
 * 权限项控制器
 */
class ItemController extends Controller
{
    protected function verbs()
    {
        return [
            'index' => ['GET'],
            'create' => ['POST'],
            'update' => ['POST'],
            'delete' => ['POST'],
            'status' => ['POST'],
            'get-drop-list' => ['GET'],
            'get-user' => ['GET'],
            'remove-user' => ['POST'],
            'get-role' => ['GET'],
            'remove-role' => ['POST'],
            'get-tree-list' => ['GET'],
        ];
    }

    /**
     * 权限项 首页
     * @return array
     * @throws HttpException
     */
    public function actionIndex()
    {
        return ItemLogic::index(getParams());
    }

    /**
     * 创建 权限项
     * @throws HttpException
     */
    public function actionCreate()
    {
        return ItemLogic::create(getParams());
    }

    /**
     * 编辑 权限项
     * @throws HttpException
     */
    public function actionUpdate()
    {
        return ItemLogic::update(getParams());
    }

    /**
     * 删除 权限项
     * @throws HttpException
     * @throws \Throwable
     */
    public function actionDelete()
    {
        return ItemLogic::delete(getParams());
    }

    /**
     * 禁用 & 启用 权限项
     * @throws HttpException
     */
    public function actionStatus()
    {
        return ItemLogic::status(getParams());
    }

    /**
     * 权限项 下拉列表
     * @return array
     */
    public function actionGetDropList()
    {
        return ItemLogic::getDropList();
    }

    /**
     * 权限项 下 用户列表
     * @return array
     * @throws HttpException
     */
    public function actionGetUser()
    {
        return ItemLogic::getUser(getParams());
    }

    /**
     * 权限项 下 移除用户
     * @throws HttpException
     */
    public function actionRemoveUser()
    {
        return ItemLogic::removeUser(getParams());
    }

    /**
     * 权限项 下 角色列表
     * @return array
     * @throws HttpException
     */
    public function actionGetRole()
    {
        return ItemLogic::getRole(getParams());
    }

    /**
     * 权限项 下 移除角色
     * @throws HttpException
     */
    public function actionRemoveRole()
    {
        return ItemLogic::removeRole(getParams());
    }

    /**
     * 权限项 树形 （ 角色、岗位、用户 授权用 ）
     * @return mixed
     */
    public function actionGetTreeList()
    {
        return ItemLogic::getTreeList();
    }
}